package cn.wzvtc.ch11query.controller;

import cn.wzvtc.ch11query.entity.User;
import cn.wzvtc.ch11query.repository.UserRepository;
import cn.wzvtc.ch11query.vo.UserDepartVo;
import cn.wzvtc.ch11query.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserRepository userRepository;

    //    @GetMapping("/getByName")
//    public List<User> getByName(String userName){
//        return userRepository.getByName(userName);
//    }
//    @GetMapping("/getByName")
//    public List<String> getByName(String userName){
//        return userRepository.getByName(userName);
//    }
//
    @GetMapping("/getByName")
    public List<UserVo> getByName(String userName) {
        return userRepository.getByName(userName);
    }

    @PostMapping("/updateGender")
    public String updateGender(String userName, Integer gender) {
        userRepository.updateGender(userName, gender);
        return "success";
    }


    @GetMapping("/getUserDepartment")
    public List<UserDepartVo> getUserDepartment() {
        return userRepository.getUserDepartment();
    }

    @GetMapping("/getByName3")
    public List<User> getByName3(String userName) {
        return userRepository.getByName3(userName);
    }
}
